/* ************************************************************************************************

	Copyright (c) 2005-2006, IGR
	All Rights Reserved.
	Licensed under the Apache License version 2.0 or above.
	For more information on licensing, see:
        http://www.apache.org/licenses/


 ************************************************************************************************
 Objet RADIO
 VERSION:0.85
 DATE:16/03/2006
 ************************************************************************************************
Init parameter :
 Name:               Form name
 top:           	 Top position (in pixel)
 left:               Left position (in pixel)             
 parent:			 Reference of an HTML or a javascript element parent of the radio
 group:              Radio group
 text:               Label of the radio
 checked             True if radio is checked
 className           classname to use for the text
 
*************************************************************************************************/
 
 
// *************************************
// CONSTRUCTOR
// *************************************



rialto.widget.Radio=function(name,top,left,parent,group,text,checked,className){
	
	//base object parameter
    var objParam=new Object;
  	objParam.name=name;
	objParam.type="radio";
    objParam.left=left;
	objParam.top=top;
	
	//base constructor
	this.base = rialto.widget.AbstractComponent;    
    this.base(objParam);
	this.base=null;
	//release object
	objParam=null;
	
	//default value
    this.className = "libNormal";	
    this.checked = false;        
	this.tabindex=rialto.widget.Form.prototype.tabIndex++;
    this.group=group;
    this.text=text;        
    
    //classname
    if (rialto.lang.isString(className)){
		this.className = className;
    }
    //checked
    if (rialto.lang.isBoolean(checked)){
		this.checked = checked;
    }
       
    // *******************************************
	// GENERATION OF DOM ELEMENTS
	// *******************************************
	
    this.divExt.id = this.id + "_divExt";
    this.divExt.style.position = this.position;
    this.divExt.style.left = this.left + "px";
    this.divExt.style.top = this.top + "px";        
    
    var oThis=this;
    
    
    //Input (with innerHTML because bug with DOM creation ---> can't be clicked!!!)
    var wInnerHTML = "";
    wInnerHTML = '<input type="radio" id="' + this.id + '" name="' + this.group+'" value="'+ this.name+'"  />';
    this.divExt.innerHTML += wInnerHTML;

    this.radio=this.divExt.firstChild;    
    this.radio.tabIndex = this.tabindex;
    // Label
    this.lib=new rialto.widget.Label("LIB1",2,20,this.divExt,this.text,this.className,{position:'absolute'});              

    //Adapt the width with the text width
    this.divExt.style.width=this.lib.getTailleTexte()+20;
    
               
    //onclick method
    this.radio.onclick=function(){                
        oThis.onclick();         
    }
        
    //Add to the parent
    if (parent) {this.placeIn(parent);};          
}

rialto.widget.Radio.prototype = new rialto.widget.AbstractComponent;

rialto.widget.Radio.prototype.adaptToContext =function(){
	//Just to put the initial check
    this.radio.checked = this.checked;
}


//return the check status
rialto.widget.Radio.prototype.getCheck=function() {
    return this.radio.checked;
}
//******those 2 METHODS ARE DEPRECATED...USE SETCHECK
//to check
rialto.widget.Radio.prototype.coche=function() {
	rialto.deprecated('Radio','coche','setCheck(true)');
    this.setCheck(true);
}

//to uncheck
rialto.widget.Radio.prototype.decoche=function() {
	rialto.deprecated('Radio','decoche','setCheck(false)');
    this.setCheck(false);   
}
//******

//this method will allow to  check and uncheck according to the parameter
rialto.widget.Radio.prototype.setCheck=function(check,boolC) {
	this.radio.checked  = check;
	this.checked=check;    
}

rialto.widget.Radio.prototype.release=function(){
    this.radio.onclick=null;
    this.lib.remove();    
}

